Check if a Python String Contains a Substring – Real Python

您所在的位置:网站首页 pandas str contains 多个 Check if a Python String Contains a Substring – Real Python

Check if a Python String Contains a Substring – Real Python

2023-04-06 14:51| 来源: 网络整理| 查看: 265

Check if a Python String Contains a Substring Martin Breuss

Martin Breuss 18 Lessons 49m basics best-practices

If you’re new to programming or come from a programming language other than Python, you may be looking for the best way to check whether a string contains another string in Python.

Identifying such substrings comes in handy when you’re working with text content from a file or after you’ve received user input. You may want to perform different actions in your program depending on whether a substring is present or not.

In this video course, you’ll focus on the most Pythonic way to tackle this task, using the membership operator in. Additionally, you’ll learn how to identify the right string methods for related, but different, use cases.

Finally, you’ll also learn how to find substrings in pandas columns. This is helpful if you need to search through data from a CSV file.

Get Started Confirm That a Python String Contains Another String

3 Lessons 10m

1. Check if a Python String Contains a Substring (Overview) 02:00

2. Confirm the Presence of a Substring 04:31

3. Generalize Your Substring Check 04:10

Find Out More About the Substring

4 Lessons 12m

1. Learn More Using String Methods 01:49

2. Use .count() to Get the Number of Occurrences 02:30

3. Use .index() to Get the Location of the Substring 02:35

4. Avoid Using .find() to Check for Substrings 05:20

Find a Substring With Conditions Using Regex

6 Lessons 17m

1. Get to Know Regex for Finding Substrings 01:32

2. Match a Substring Using re.search() 03:51

3. Explore a Match Object 03:25

4. Find All Pattern Matches 03:28

5. Get All Matches as Match Objects 03:26

6. Wrap Up Finding Substrings With Regex 01:51

Find a Substring in a pandas DataFrame Column

3 Lessons 6m

1. Set Up and Inspect the Data 02:10

2. Filter DataFrame Rows With .str.contains() 02:03

3. Use Regular Expressions With pandas 02:23

Review What You've Learned

2 Lessons 2m

1. Check if a Python String Contains a Substring (Quiz)

2. Check if a Python String Contains a Substring (Summary) 02:22

Get Started

About Martin Breuss

Martin Breuss Martin Breuss

Martin likes automation, goofy jokes, and snakes, all of which fit into the Python community. He enjoys learning and exploring and is up for talking about it, too. He writes and records content for Real Python and CodingNomads.

» More about Martin

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Aldren Santos

Aldren

Christopher Bailey

Christopher

Kate Finegan

Kate

Tappan Moore

Tappan

Geir Arne Hjelle

Geir Arne

Ian Currie

Ian



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3